package com.base.controller;

import com.base.po.tbk.TbkBrandCategory;
import com.base.po.voip.SelfShop;
import com.base.po.voip.SelfShopCategory;
import com.base.po.voip.Users;
import com.base.service.SelfShopCategoryService;
import com.base.service.SelfShopService;
import com.base.service.TbkBrandCategoryService;
import com.base.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 自营商城分类
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin")
public class index_TbkBrandCategory {
	@Autowired
	private TbkBrandCategoryService tbkBrandCategoryService;
	@Autowired
	private UsersService usersService;

	// 自营商城分类首页
	@RequestMapping("/tbkBrandCategory")
	public ModelAndView index(HttpServletRequest request) throws Exception {
		// 返回ModelAndView
		ModelAndView modelAndView = new ModelAndView();
		String adminUserId = (String) request.getSession().getAttribute("adminUserId");
		Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
	
		Users users = usersService.selectByPrimaryKey(adminUserId);
		List<TbkBrandCategory> tbkBrandCategory = null;
		if(users.getRole() == 0 || users.getRole() == 1) {
			tbkBrandCategory = tbkBrandCategoryService.selectByLevel1(adminUserId,adminUserId);
		}
		if(users.getRole() == 2) {
			tbkBrandCategory = tbkBrandCategoryService.selectByLevel1(users.getParentid(),users.getParentid());
		}
		
		request.setAttribute("tbkBrandCategory", tbkBrandCategory);
		request.setAttribute("adminUsergrade", adminUsergrade);
		// 设置页面进行跳转
		modelAndView.setViewName("jsp/index_TbkBrandCategory");
		return modelAndView;
	}
}
